//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CBaseVertex9.h>
///	@path	~/src/graphics/dx9/
///	@date	2007/10/25
///	@desc	Base vertex implementation in DX9.

#pragma once

#include "xeres.h"

#include "graphics/IVertexBuffer.h"
#include "graphics/IVertexLayout.h"
#include "graphics/dx9/CDevice9.h"

namespace xeres {

	/*! 
		\class	CBaseVertex9
		\brief
	*/
	class CBaseVertex9 : public IVertexBuffer
	{
	protected:

		/// \ctor
		CBaseVertex9( IDirect3DVertexBuffer9 * buffer , size_t count , size_t stride );

		/// \dtor
		virtual ~CBaseVertex9( void );

		DECL_IOBJECT_CLASS( CBaseVertex9 , IVertexBuffer );

	public:

		/// \impl
		virtual bool OnLostDevice( void );

		/// \impl
		virtual bool OnResetDevice( RefWeak<IDevice> device );

		/// \name Vertex Buffer Interface
		//@{

		/// \impl
		virtual size_t GetCount( void );

		/// \impl
		virtual size_t GetSize( void );

		/// \impl
		virtual bool IsWritable( void );

		/// \impl
		virtual bool IsReadable( void );

		/// \impl
		virtual bool Map( bool discard , ResourceMap& data );

		/// \impl
		virtual bool ReadBack( ResourceMap& data , bool readonly );

		/// \impl
		virtual bool Unmap( void );

		/// \impl
		virtual IUnknown * GetVertexInterface( void );

		/// \impl
		virtual IUnknown * GetIndexInterface( void );

		/// \impl
		virtual uint GetStreamCount( void );

		/// \impl
		virtual void ApplyStream( RenderContext& rc , uint offset_vertex );

		//@}

	protected:

		//@ data
		IDirect3DVertexBuffer9 *	m_pBuffer;
		size_t						m_vertexCount;
		size_t						m_stride;
		D3DVERTEXBUFFER_DESC		m_desc;
	};

} // namespace xeres
